package com.mybatisplus.service.impl;

import com.mybatisplus.entity.SignData;
import com.mybatisplus.mapper.StudentMapper;
import com.mybatisplus.service.SignService;
import com.mybatisplus.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Auto created By IntelliJ IDEA
 *
 * @author : gzrong
 * @Date : 2023/5/7 13:35
 */
@Service
public class SignServiceImpl implements SignService {
    @Autowired
    StudentMapper studentMapper;

    //    插入
    @Override
    public boolean intoSign(String name, String stuid) {
//        先做查询
        String DBstuname = studentMapper.selectNameByStuid(stuid);

        if (name.equals(DBstuname)) {
            //数据库存在该学生时执行
            studentMapper.intoSignRob(name, stuid);
//            boolean exist = studentMapper.isExist(stuid);
            return true;
        } else
            //数据库不存在该学生时返回false
            return false;
    }

    @Override
    public DataVO<SignData> selectSign(String stuid) {
        DataVO<SignData> data = new DataVO<>();
        List stuList = studentMapper.selectSignData(stuid);
        data.setData(stuList);
        return data;
    }

    @Override
    public DataVO<SignData> selectAllInSign() {
        DataVO<SignData> dataVO = new DataVO<>();
//        List<SignData> signData = studentMapper.selectAllSignData();
//        String jsonOutput= JSON.toJSONString(signData);
        dataVO.setData(studentMapper.selectAllSignData());
        return dataVO;
    }

    @Override
    public DataVO<SignData> selectNotSigned() {
        DataVO<SignData> data = new DataVO<>();
        data.setData(studentMapper.selectNotSigned());
        return data;
    }

    @Override
    public void clean() {
        studentMapper.clean();
    }

    @Override
    public boolean isAlreadySigned(String stuid) {
        String name = studentMapper.isExist(stuid);
        return name != null;
    }

    @Override
    public List<SignData> getTableData() {
        return studentMapper.fromTables();
    }
}
